/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package evaluation;

import drt.Naming;

/**
 *
 * @author phong
 */
public class Vertex {
    
    String label;
    String id;
    int type;
    
    public static final int TYPE_PRED = 0;
    public static final int TYPE_REF = 1;
    public static final int TYPE_OPT = 2;
    public static final int TYPE_LABEL = 3;
    
    public Vertex(String label, int type) {
        this.label = label;
        this.type = type;
        switch (type) {
            case TYPE_PRED: this.id = Naming.getUniqueName("p0"); break;
            case TYPE_REF: this.id = Naming.getUniqueName("r0"); break;
            case TYPE_OPT: this.id = Naming.getUniqueName("o0"); break;
            case TYPE_LABEL: this.id = Naming.getUniqueName("l0"); break;
        }
    }
    
    public static Vertex createNeg() {
        return new Vertex("-", TYPE_OPT);
    }
    
    public static Vertex createEq() {
        return new Vertex("=", TYPE_OPT);
    }
    
    public static Vertex createImp() {
        return new Vertex("->", TYPE_OPT);
    }
    
    public static Vertex createOr() {
        return new Vertex("V", TYPE_OPT);
    }
    
    public static Vertex createWhq() {
        return new Vertex("?", TYPE_OPT);
    }
    
    public static Vertex createPos() {
        return new Vertex("POS", TYPE_OPT);
    }
    
    public static Vertex createNec() {
        return new Vertex("NEC", TYPE_OPT);
    }
    
    public static Vertex createIs() {
        return new Vertex(":", TYPE_OPT);
    }

    public int getType() {
        return this.type;
    }
    
    public String getLabel() {
        return this.label;
    }
    
    @Override
    public String toString() {
        return this.label;
    }
    
    @Override
    public boolean equals(Object other) {
        if (other instanceof Vertex) {
            Vertex that = (Vertex)other;
            
            if (that.type != this.type)
                return false;
            if (type == TYPE_PRED || type == TYPE_OPT)
                return this.label.equals(that.label) && this.id.equals(that.id);
            else 
                return this.label.equals(that.label);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return this.label.hashCode();
    }
}
